import { initGlobalState, MicroAppStateActions } from 'qiankun'

// 初始化 state
const state = {
  name: '张三',
  age: 20
}
const actions: MicroAppStateActions = initGlobalState(state)
//  state监听 第二个参数为true时，会立即执行
actions.onGlobalStateChange((state, prev) => {
  // state: 变更后的状态; prev 变更前的状态
  console.log(state, prev)
})
// 修改state
actions.setGlobalState({
  age: 21
})
setTimeout(() => {
  actions.setGlobalState({
    age: 22
  })
}, 10000)
// 关闭state监听
// actions.offGlobalStateChange()

export default actions
